package jwdt.xadmin.info.action;

import jwdt.common.action.BaseAction;
import jwdt.xadmin.info.bean.TType;
import jwdt.xadmin.info.service.TypeManageService;
import jwdt.xadmin.system.bean.TUser;

import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Controller;
import com.ezerg.web.annotation.RequestMapping;

@Controller("/xadmin/info")
public class TypeManageAction extends BaseAction {
	
	TypeManageService typeService = (TypeManageService)app.getBean("TypeManageService");
	
	/**
	 * 选择发布栏目
	 */
	@RequestMapping("/typeTree")
	public Page doTypeTree(Form f, Module m)throws Exception {
		TUser userInfo = (TUser)f.getSession("userInfo");
		String jsdm = userInfo.getOskey();
		return m.getJsonPage(f, typeService.listTypeForTree(jsdm));
	}
	
	/**
	 * 选择全部栏目
	 */
	@RequestMapping("/alltypeTree")
	public Page doAllNewsLeft(Form f, Module m)throws Exception {
		return m.getJsonPage(f, typeService.listTypeForTree());
	}
	
	/**
	 * 选择全部栏目（包括禁用）
	 */
	@RequestMapping("/typeLeftTree")
	public Page doNewsLeft(Form f, Module m)throws Exception {
		return m.getJsonPage(f, typeService.listAllTypeForTree());
	}
	
	@RequestMapping("/selectType")
	public Page doSelectType(Form f, Module m) throws Exception {
		int fid = f.getInt("fid", 0);
		PageUtil pu = (PageUtil) f.copy2Class(PageUtil.class);
		return m.getWritePage(f, typeService.selectTypeList(pu, fid).toJson());
	}
	
	@RequestMapping("/selectOneType")
	public Page doEdit(Form f, Module m) throws Exception {
		int typeid = f.getInt("typeid");
		return m.getJsonPage(f, typeService.selectOneType(typeid));
	}
	
	@RequestMapping("/saveType")
	public Page doSaveType(Form f, Module m) throws Exception {
		int typeid = f.getInt("id");
		TType obj = (TType)f.copy2Class(TType.class);
		return m.getWritePage(f, typeService.saveType(typeid, obj));
	}
	
	@RequestMapping("/delType")
	public Page doDelType(Form f, Module m) throws Exception {
		int typeid = f.getInt("typeid");
		return m.getWritePage(f, typeService.delType(typeid));
	}

}
